package com.siyuanren.gcocp.enums.wx;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @author guwr
 */
@Getter
public enum GradeEnum {
    GRADE_JUNIOR("初级学员", 1, 0, 150),
    GRADE_MIDDLE("中级学员", 2, 150, 300),
    GRADE_HIGH("高级学员", 3, 300, 450),
    GRADE_SUPER("尊享学员", 4, 450, 999);

    private String desc;
    private int value;
    private int score;
    private int nextScore;

    GradeEnum(String desc, int value, int score, int nextScore) {
        this.desc = desc;
        this.value = value;
        this.score = score;
        this.nextScore = nextScore;
    }

    public static GradeEnum getModel(int value) {
        for (GradeEnum he : GradeEnum.values()) {
            if (Objects.equals(value, he.getValue())) {
                return he;
            }
        }
        return null;
    }

    /**
     * 根据积分加载用户积分等级
     *
     * @param score
     * @return
     */
    public static GradeEnum getModelByScore(int score) {
        if (score >= GRADE_SUPER.score) {
            return GRADE_SUPER;
        } else if (score >= GRADE_HIGH.score) {
            return GRADE_HIGH;
        } else if (score >= GRADE_MIDDLE.score) {
            return GRADE_MIDDLE;
        }
        return GRADE_JUNIOR;
    }

    public static String getEnumDesc(Integer value) {
        if (value == null) {
            return StringUtils.EMPTY;
        }
        GradeEnum model = getModel(value);
        if (model == null) {
            return StringUtils.EMPTY;
        }
        return model.getDesc();
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public void setNextScore(int nextScore) {
        this.nextScore = nextScore;
    }
}